package com.pandaroid.pandaclockv1;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class WebViewActivity extends Activity {
	final Activity activity = this;
	ProgressDialog mProgress;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.webview);
	    
	    WebView infoWebView = (WebView)findViewById(R.id.webView01);
	    
	    infoWebView.setWebViewClient(new InfoWebViewClient());
	    
	    infoWebView.getSettings().setJavaScriptEnabled(true);
	    
	    // Load URL
	    infoWebView.loadUrl("http://blog.naver.com/man8408/110115898419");
	}
	    
    public class InfoWebViewClient extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			 
			return true;
		}
		
		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			if (mProgress == null) {
				mProgress = new ProgressDialog(activity);
			    mProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
			    mProgress.setTitle("Loading...");
			    mProgress.setMessage("Please wait for few second...");
			    mProgress.setCancelable(false);
			    mProgress.setButton("Cancel", new DialogInterface.OnClickListener() {
				    @Override
				    public void onClick(DialogInterface dialog, int whichButton) {
				    	mProgress.dismiss();
					}
			    });
				mProgress.show();
			}
		}
		  
		@Override
		public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
			Toast.makeText(activity, "Loading Error" + description, Toast.LENGTH_SHORT).show();
		   
			if (mProgress.isShowing()) {
				mProgress.dismiss();
			}
		}
		  
		@Override
		public void onPageFinished(WebView view, String url) {
			if (mProgress.isShowing()) {
			mProgress.dismiss();
			}
		}
    }
}
